/**
 * @Author wywinstonwy
 * @Date 2022/1/8 9:30 下午
 * @Description:
 */

import 'package:demo202112/utils/common_appbar.dart';
import "package:flutter/material.dart";

class MyChips extends StatefulWidget {
  const MyChips({Key? key}) : super(key: key);

  @override
  _MyChipsState createState() => _MyChipsState();
}

class _MyChipsState extends State<MyChips> {
  bool _selected = false;
  int _selectedIndex = 0;
  List<String> _filters = [];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar('Chips'),
      body: Column(
        children: [
          _buildFilterChip()

        ],
      ),
    );
  }
  _buildFilterChip(){
    return Column(

      children: [
        Wrap(
          spacing: 15,
          children: List.generate(10, (index) {
            return FilterChip(
              label: Text('测试 $index'),
              selected: _filters.contains('$index'),
              onSelected: (v) {
                setState(() {
                  if(v){
                    _filters.add('$index');
                  }else{
                    _filters.removeWhere((f){
                      return f == '$index';
                    });
                  }
                });
              },
            );
          }).toList(),
        ),
        Text('选中：${_filters.join(',')}'),

      ],
    );
  }
  _buildChoiceChip(){
    return  Wrap(
      spacing: 5,
      children: List.generate(20, (index){
        return ChoiceChip(
          label: Text('测试 $index'),
          selected: _selectedIndex==index,
          onSelected: (v){
            setState(() {
              _selectedIndex =index;
            });
          },

        );
      }).toList(),

    );
  }
  _buildChios(){
    return Column(children: [ const RawChip(
      label: Text('RawChip'),
      isEnabled: false, //禁止点选状态
    ),
      const RawChip(
        avatar: CircleAvatar(
          child: Text('R'),
        ),
        label: Text('RawChip'),
        // isEnabled: false,//禁止点选状态
      ),
      const RawChip(
        avatar: CircleAvatar(
          child: Text('R'),
        ),
        label: Text('RawChip'),
        // isEnabled: false,//禁止点选状态
        labelPadding: EdgeInsets.symmetric(horizontal: 20),
        padding: EdgeInsets.only(left: 10, right: 10, top: 5),
      ),
      RawChip(
        label: Text('RawChip'),
        onDeleted: () {
          print('onDeleted');
        },
        deleteIcon: Icon(Icons.delete),
        deleteIconColor: Colors.red,
        deleteButtonTooltipMessage: "删除",
        // isEnabled: false,//禁止点选状态
        labelPadding: EdgeInsets.symmetric(horizontal: 10),
        padding: EdgeInsets.only(left: 10, right: 10, top: 5, bottom: 5),
      ),
      RawChip(
        label: Text('RawChip'),
        shape:
        RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
        backgroundColor: Colors.blue,
        padding: EdgeInsets.symmetric(vertical: 10),
        elevation: 8,
        shadowColor: Colors.grey,
      ),
      RawChip(
        label: Text('RawChip'),
        selected: _selected,
        onSelected: (v) {
          setState(() {
            _selected = v;
          });
        },
        selectedColor: Colors.blue,
        selectedShadowColor: Colors.red,
        showCheckmark: true,
        //勾选状态
        pressElevation: 12, //点击效果
      ),
      Chip(label: Text('Chip')),
      InputChip(
        avatar: const CircleAvatar(
          radius: 12.0,
        ),
        label: const Text(
          'InputChip',
          style: TextStyle(fontSize: 12.0),
        ),
        shadowColor: Colors.grey,
        deleteIcon: const Icon(
          Icons.close,
          color: Colors.black54,
          size: 14.0,
        ),
        onDeleted: () {
          print('onDeleted');
        },
        onSelected: (bool selected) {
          setState(() {
            _selected = selected;
          });
        },
        selectedColor: Colors.orange,
        disabledColor: Colors.grey,
        selected: _selected,
        materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
        labelStyle: TextStyle(color: Colors.black54),
      ),],);
  }
}
